/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-07-09 19:31:47
 * @LastEditTime: 2022-07-09 19:39:53
 * @LastEditors: liutq
 * @Reference:
 */
package admin

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/maxyang107/jinglan/common"
	"github.com/maxyang107/jinglan/service"
)

/**
 * @description: 方法描述：编辑或新增banner
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func AddOrModifyBanner(c *gin.Context) {
	var param common.Banner
	if err := c.ShouldBind(&param); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}

	err := service.BannerService.AddOrModifyBanner(param)
	if err != nil {
		common.ResponseToJson(http.StatusOK, common.Fail, err.Error(), c)
		return
	}
	common.ResponseToJson(http.StatusOK, common.Ok, "success", c)
}

func GetBannerList(c *gin.Context) {
	bl := service.BannerService.GetBannerListForAdmin()
	common.ResponseDetailToJson(int(http.StatusOK), bl, "success", c)
}
